package org.eenie.learn.seedquartz.api;

import java.util.HashMap;
import java.util.Map;

public class ApiResponse {

    private int code;
    private String message;
    private Object data;
    private long timestamp;

    private ApiResponse() {
    }

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public Object getData() {
        return data;
    }

    public void setData(Object data) {
        this.data = data;
    }


    public long getTimestamp() {
        return timestamp;
    }

    public void setTimestamp(long timestamp) {
        this.timestamp = timestamp;
    }

    public static ApiResponse success(Object data) {
        ApiResponse response = new ApiResponse();
        response.code = 0;
        response.message = "success";
        response.data = data;
        response.timestamp = System.currentTimeMillis();
        return response;
    }

    public static ApiResponse success(String key, Object value) {
        ApiResponse response = new ApiResponse();
        response.code = 0;
        response.message = "success";
        response.timestamp = System.currentTimeMillis();
        Map<String, Object> data = new HashMap<>();
        data.put(key, value);
        response.data = data;
        return response;
    }


    public static ApiResponse fail(int code, String msg) {
        ApiResponse response = new ApiResponse();
        response.code = code;
        response.message = msg;
        response.timestamp = System.currentTimeMillis();

        return response;
    }


}
